package com.ytwl.service;

import com.ytwl.mapper.CarriersMapper;
import com.ytwl.bean.Carriers;
import com.ytwl.bean.User;
import com.ytwl.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CarriesService {
    @Autowired
    CarriersMapper carriersMapper;
    public Integer addTask(Carriers carriers) {
        carriers.setCheckintime(new Date());
//        carriers.setFkUserid(((User) SecurityUtils.getSubject().getSession().getAttribute("user")).getUserid());
        return carriersMapper.insertSelective(carriers);
    }

    public Long getTotal() {
        return carriersMapper.getTotal(UserUtils.getCurrentUser().getUserid());
    }

    public List<Carriers> getAllCarriesByPage(Integer page, Integer size) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        return carriersMapper.getAllCarriesByPage(page,size,UserUtils.getCurrentUser().getUserid());
    }

    public Integer deleteCarriersById(Integer id) {
        return carriersMapper.deleteByPrimaryKey(id);
    }

    public Integer updateCarriersById(Carriers carriers) {
        return carriersMapper.updateByPrimaryKeySelective(carriers);
    }
}
